<template>
  <div class="container">
    <Navbars ></Navbars>
    <!-- 条件 -->
    <div class="querydiv" shadow="never">
      <el-form :inline="true" size="medium" label-width="100px">
        <el-form-item label="当前系统版本">
          <el-tag class="btncolor tagcolor">{{version}}</el-tag>
        </el-form-item>
        <el-form-item label="" prop="status">
          <el-select v-model="formDatas.sys" placeholder="请选择需要升级的系统">
            <el-option
              v-for="item in statuslist"
              :key="item.code"
              :label="item.name"
              :value="item.code">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="上传程序版本包" label-width="120px">
          <el-upload
            class="upload-demo"
            action="#"
            :show-file-list="false"
            :http-request="fnUploadRequest">
            <el-button size="small" type="primary" class="btncolor btn">点击上传</el-button>
          </el-upload>
        </el-form-item>
        <el-form-item>
          <el-button class="btn btncolor" :disabled="disabled" type="primary" @click="handleupgrade">开始升级</el-button>
        </el-form-item>
      </el-form>
    </div>
    <!-- 表格 -->
    <div class="mt15">
      <el-card class="tab-card" shadow="never">
        <div slot="header" class="spacebetween disflex align-center">
          <span style="color:#676a6f;font-size:14px">登录日志列表</span>
        </div>
        <el-table :data="tableData" :header-cell-style="{background:'#e4ebfd',color:'#7690db'}" :row-class-name="tableRowClassName"
            default-expand-all row-key="id" :tree-props="{children: 'children', hasChildren: 'hasChildren'}">
            <el-table-column align="center" prop="id"  label="ID" ></el-table-column>
            <el-table-column align="center" prop="type"  label="所属系统" ></el-table-column>
            <el-table-column align="center" prop="filename" label="	应用名称"></el-table-column>
            <el-table-column align="center" prop="commonds" label="执行指令"></el-table-column>
            <el-table-column align="center" prop="results" label="升级结果"></el-table-column>
            <el-table-column align="center" prop="createTime" label="升级时间"></el-table-column>
        </el-table>
      </el-card>
      <!--分页 -->
      <Pagination :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.num" @pagination="getList"></Pagination>
    </div>
  </div>
</template>

<script>
import { upgradepage,version,upgradesend,upload} from '@/api/home.js'
import { dicttype } from "@/api/role.js";
import Pagination from '@/components/Pagination'
export default {
  name: 'user',
  components: { Pagination },
  data() {
    return {
      total: 0,
      listLoading: true,
      listQuery: {
        page:1,
        num:10,
      },
      tableData: [],
      version:'',
      statuslist:[],
      formDatas:{
        sys:'',
        path:''
      },
      disabled:true,
      // baseUrl: process.env.VUE_APP_BASE_API + '/file-center/api/v1/file/download?fileName=',
    }
  },
  created() {
    this.getversion()
    this.getList()
    this.getDIctyp()
  },
  methods: {
    // 设置表格颜色
    tableRowClassName({row, rowIndex}) {
      if (rowIndex%2==0) { return 'warning-row'}
      return '';
    },
    // 获取状态字典
    getDIctyp(){
      this.$getFlag().then(obj=>{
        dicttype({type:'upgrade_type'},obj.data).then(res=>{
          if(res.status == 200){
            this.statuslist = res.data
          }
        })
      })
    },
    // 获取表格列表信息
    getList() {
      this.OrganList = []
      this.$getFlag().then(obj=>{
        this.listLoading = false
        upgradepage(this.listQuery,obj.data).then(response => {
          this.tableData = response.list
          this.total = Number(response.total)
          setTimeout(() => {
            this.listLoading = false
          }, 1.5 * 1000)
        })
      })
    },
    //版本
    getversion(){
      this.$getFlag().then(obj=>{
        version(obj.data).then(res=>{
          if(res.status = 200){
            this.version = res.data
          }
        })
      })
    },
    // 上传
    fnUploadRequest(item){
      const formData = new FormData()
      formData.append('file', item.file)
      this.$getFlag().then(obj=>{
        upload(formData,obj.data).then(res=>{
          console.log(res)
          this.disabled = false
        })
      })
    },
    // 升级
    handleupgrade(){
      this.$getFlag().then(obj=>{
        upgradesend(this.formDatas,obj.data).then(res=>{
          if (response.status == 200) {
            this.$notify({title: "操作成功", message: "添加成功",  type: "success",  duration: 2000,});
            this.getList();
          } else {
            this.$notify({  title: "操作失败",  message: response.msg,  type: "error",  duration: 2000,});
          }
        })
      })
      
    }
  }
}
</script>

<style scoped lang="scss">
::v-deep .stafftree .el-tree-node__content .el-checkbox .el-checkbox__input {
  display: none;
}
</style>
<style>
  .el-table .warning-row {
    background: #f6f9fe;
  }
  .tagcolor{
    color:#fff
  }
</style>
